package tmproject.hlhj.fhp.cartrans.modules

import android.content.Context
import com.example.mymvp.BaseModule
import com.lzy.okgo.model.Response
import tmproject.hlhj.fhp.cartrans.convert.MyException
import tmproject.hlhj.fhp.cartrans.http.Apis
import tmproject.hlhj.fhp.cartrans.http.BaseObserver
import tmproject.hlhj.fhp.cartrans.http.LoadingAction
import tmproject.hlhj.fhp.cartrans.javaBean.BaseBean
import tmproject.hlhj.fhp.cartrans.javaBean.UserInfoBean
import tmproject.hlhj.fhp.cartrans.utils.SpHelper
import tmproject.hlhj.fhp.cartrans.utils.ToastUtils
import java.io.File

/**
 * Created by Never Fear   on 2018\8\28 0028.
Never More....
 */
class UserCenterModule :BaseModule {
    var listener:OnUserInfoListener?=null

    fun getUserInfo(){
        val userInfoBean = UserInfoBean()
        listener?.userInfoResp(userInfoBean)
    }

    fun changeHead(head:File,c:Context ){
        Apis.changeHead(SpHelper.getToken(c),head)
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :BaseObserver<Response<BaseBean>>(c){
                                override fun failed(e: Throwable?) {
                                    if (e is MyException){
                                        ToastUtils.toast(e.message!!)
                                    }
                                }

                                override fun httpSuccess(t: Response<BaseBean>) {
                                    listener?.changeHeadResp(t.body())
                                }

                                override fun httpErroCode(baseBean: BaseBean) {
                                }
                            })

                }
    }
    interface OnUserInfoListener{
        fun userInfoResp(userInfoBean: UserInfoBean)

        fun changeHeadResp(baseBean: BaseBean)
    }
}